package com.ronan.common.protocol;

import io.netty.buffer.ByteBuf;
import lombok.Data;

/**
 * FileName    : com.ronan.imserver.protocol
 * Description :
 *
 * @author : ysk
 * @version : 1.0
 * Create Date : 2021/2/26 0:17
 **/
@Data
public class RIMHeader implements IRIMHeader{

    /** 消息id 8 */
    private long msgNo;

    /** 指令 4 */
    private int command;

    /** 时间戳 8 */
    private long timestamp;

    /** 长度 4 */
    private int length;

    /**
     * 解码
     *
     * @param buf 缓冲区
     */
    public void decode(ByteBuf buf) {
        msgNo = buf.readLong();
        command = buf.readInt();
        timestamp = buf.readLong();
        length = buf.readInt();
    }

    /**
     * 编码
     *
     * @param buf 缓冲区
     */
    public void encode(ByteBuf buf) {
        buf.writeLong(msgNo);
        buf.writeInt(command);
        buf.writeLong(timestamp);
        buf.writeInt(length);
    }
}
